import { MessageProcessingService } from './MessageProcessingService.js';
import { MessageRepository } from '../../mongodb/repositories/MessageRepository.js';
import { TaskSessionService } from '../../mongodb/services/TaskSessionService.js';
import { TaskSessionRepository } from '../../mongodb/repositories/TaskSessionRepository.js';
import { Message, TaskSession } from '../../mongodb/models/index.js';

/**
 * 服务工厂类，用于创建和管理服务实例
 */
export class ServiceFactory {
  private static messageProcessingService: MessageProcessingService | null = null;
  
  /**
   * 获取消息处理服务实例（单例模式）
   */
  static getMessageProcessingService(): MessageProcessingService {
    if (!this.messageProcessingService) {
      // 创建仓储实例
      const messageRepository = new MessageRepository(Message);
      const taskSessionRepository = new TaskSessionRepository(TaskSession);
      
      // 创建服务实例
      const taskSessionService = new TaskSessionService(taskSessionRepository);
      
      // 创建消息处理服务
      this.messageProcessingService = new MessageProcessingService(
        messageRepository,
        taskSessionService
      );
    }
    
    return this.messageProcessingService;
  }
  
  /**
   * 清除所有服务实例（主要用于测试）
   */
  static clearInstances(): void {
    this.messageProcessingService = null;
  }
}

// 导出服务和类型
export { MessageProcessingService } from './MessageProcessingService.js';
export type { MessageProcessingResult, MessageProcessingOptions } from './MessageProcessingService.js';
